from django.db import models

from utils.models import TimeStampedModel


class Course(TimeStampedModel):
    DEGREE_CHOICES = (
        ('primary', '初级'),
        ('intermediate', '中级'),
        ('advanced', '高级')
    )
    name = models.CharField(max_length=50, verbose_name='课程名')
    description = models.CharField(max_length=300, verbose_name='课程描述')
    detail = models.TextField(verbose_name='课程详情')
    level = models.CharField(choices=DEGREE_CHOICES, max_length=15, verbose_name='课程等级')
    duration = models.IntegerField(default=0, verbose_name='课程时长')
    students = models.IntegerField(default=0, verbose_name='学习人数')
    clicks = models.IntegerField(default=0, verbose_name='点击数')
    collections = models.IntegerField(default=0, verbose_name='收藏数')
    cover = models.ImageField(upload_to='course/%Y/%m', max_length=100, verbose_name='封面图')

    class Meta:
        verbose_name = '课程'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Chapter(TimeStampedModel):
    course = models.ForeignKey(Course, verbose_name='课程', on_delete=True)
    name = models.CharField(max_length=100, verbose_name='章节名')

    class Meta:
        verbose_name = '课程章节'
        verbose_name_plural = verbose_name


class Video(TimeStampedModel):
    chapter = models.ForeignKey(Chapter, verbose_name='章节', on_delete=True)
    name = models.CharField(max_length=100, verbose_name='视频名称')

    class Meta:
        verbose_name = '章节视频'
        verbose_name_plural = verbose_name


class CourseResource(TimeStampedModel):
    course = models.ForeignKey(Course, verbose_name='课程', on_delete=True)
    name = models.CharField(max_length=100, verbose_name='资源名称')
    resource = models.FileField(upload_to='course/resource/%Y/%m', max_length=100, verbose_name='资源文件')

    class Meta:
        verbose_name = '课程资源'
        verbose_name_plural = verbose_name
